package com.he.hsdyc.controller;

import com.he.hsdyc.common.token.TokenUtils;
import com.he.hsdyc.model.User;
import com.he.hsdyc.model.msg.ErrorCode;
import com.he.hsdyc.model.msg.Message;
import com.he.hsdyc.model.vo.AccountVO;
import com.he.hsdyc.model.vo.UserVo;
import com.he.hsdyc.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@Slf4j
@Api(value="UserController",description="用户信息",tags={"用户管理"})
@RequestMapping("user")
public class UserController {

    private final UserService userService;

    //spring4后官方推荐使用构造方法作为依赖注入方式
    @Autowired
    public UserController(UserService userService) {
        this.userService = userService;
    }

    @ApiOperation("查询用户列表")
    @RequestMapping(value = "all",method = RequestMethod.POST)
    public Message queryUser(HttpServletRequest request, @RequestBody UserVo vo) {
//        User user = TokenUtils.analysisToken(request);
//        log.warn("你可以这样在代码中获取你所需要的用户信息,如当前登录人的名称为："+user.getName());
        List<User> list = userService.findAll(vo);
        return new Message(ErrorCode.SUCCESS,list);
    }

}
